<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib prefix="sys" uri="/WEB-INF/tld/sys.tld" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>保单基础信息表 管理</title>
    <style type="text/css">
        .searchArea .fieldBox .label{width: 70px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;}
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">保险公司</div>
                    <div class="field">
                        <input name="insCompId" id="insCompId" data-value="" placeholder="请选择" ltype="combobox">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">客户名称</div>
                    <div class="field">
                        <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">客户经理</div>
                    <div class="field">
                        <input name="cstMgrNm" id="cstMgrNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">保单号</div>
                    <div class="field">
                        <input name="plcNo" id="plcNo" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">支付表号</div>
                    <div class="field">
                        <input name="paySchNo" id="paySchNo" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">保单起始日期</div>
                    <div class="field">
                        <input ligerui="width:82" name="plcEndTmMin" id="plcEndTmMin" type="text" class="ui-datepicker" value="">-
                        <input ligerui="width:82" name="plcEndTmMax" id="plcEndTmMax" type="text" class="ui-datepicker" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">保单到期日期</div>
                    <div class="field">
                        <input ligerui="width:82" name="plcBgTmStart" id="plcBgTmStart" type="text" class="ui-datepicker" value="">-
                        <input ligerui="width:82" name="plcBgTmEnd" id="plcBgTmEnd" type="text" class="ui-datepicker" value="">
                    </div>
                </div>
                <div class="clearFix"></div>
                <div class="btnsBox">
                    <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                    <span id="clearBtn" class="sq-button sq-button-round">清空</span>
                    <span id="changeBtn" class="sq-button sq-button-round">修改</span>
                    <sys:funcAuth resCd="createInsSubComp">
                        <span id="apprBtn" class="sq-button sq-button-round">批单</span>
                        <span id="renewBtn" class="sq-button sq-button-round">计入/不计入续保</span>
                    </sys:funcAuth>
                    <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                    <%--<span id="delBtn" class="sq-button sq-button-round">删除</span>--%>
                </div>

            </div>
        </form>
    </div>
    <div id="ligergrid1" class="sq-grid"></div>
</div>

<script type="text/javascript">
    var grid = null;
    $(function () {
        grid = $("#ligergrid1").ligerGrid({
            url: '<%=path%>/insurance/insPlcBscInfo/initList.do',
            method: 'get',
            columns: [
                {display: '客户名称', name: 'cstNm', minWidth: 100, align: 'left', enabledSort: false,
                    render:function(rowdata,rowindex,value){
                        return '<a href="javascript:;" onclick="showCstDtl('+rowdata.cstId+')"><span class="gridTip" title="客户查看">'+rowdata.cstNm+'</span></a>';
                    }
                },
                {display: '保单号', name: 'plcNo', minWidth: 100, align: 'left', enabledSort: false,
                    render:function(rowdata,rowindex,value){
                        if(!value||value==null||value=='null'){
                            return '<a href="javascript:;" onclick="queryPlcDtl('+rowdata.id+')">保单</a>';
                        }
                        return '<a href="javascript:;" onclick="queryPlcDtl('+rowdata.id+')"><span class="gridTip" title="保单查看">'+rowdata.plcNo+'</span></a>';
                    }
                },
                {display: '保险种类', name: 'insTypCdNm', minWidth: 100, align: 'center', enabledSort: false},
                {display: '保险公司', name: 'insCompNm', minWidth: 100, align: 'left', enabledSort: false},
                /*{display: '保险支公司', name: 'insCompSubNm', minWidth: 100, align: 'left', enabledSort: false},*/
                {display: '购买方式', name: 'buyWayCdNm', minWidth: 100, align: 'left', enabledSort: false},
                {display: '被保险人', name: 'insPerNm', minWidth: 100, align: 'left', enabledSort: false},
                 {display: '保费总金额', name: 'insTtlFee', minWidth: 100, align: 'right', enabledSort: false,
                    render:function(rowdata,rowid,value){
                        return '&yen;'+FormatMoney(rowdata.insTtlFee/100);
                    }
                 },
                {display: '续保状态', name: 'reneStsCdNm', minWidth: 100, align: 'center', enabledSort: false},
                /*{display: '起保时间', name: 'plcBgTm', minWidth: 100, align: 'left', enabledSort: false,render: renderDate },*/
                {display: '止保时间', name: 'plcEndTm', minWidth: 100, align: 'left', enabledSort: false,render: renderDate},
                {display: '保单性质', name: 'plcPropCdNm', minWidth: 100, align: 'center', enabledSort: false},
                {display: '计入续保？', name: 'isRene', minWidth: 100, align: 'left', enabledSort: false,
                    render:function(rowdata,rowid,value){
                        if(rowdata.isRene==0){
                            return '不计入续保';
                        }else{
                            return '计入续保';
                        }
                    }
                },
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: true,
            rownumbers: false,
            allowUnSelectRow: true,
            alternatingRow: false,
            groupColumnName:'paySchNo',
            groupColumnDisplay:'支付表号',
        });
        grid.setHeight(100);

        $("#insCompId").ligerComboBox({
            valueField: 'id',
            textField: 'compNm',
        });
        $("#searchBar").ligerForm();
        liger.get("insCompId").setData(${insCompList});

        $("#pageloading").hide();

        /* 查询 */
        $("#searchBtn").click(function (event) {
            var form = liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
        });

        /* 清空 */
        $("#clearBtn").click(function (event) {
            clearLigerForm("searchBar");
        });

        var callback = function () {
            grid.reload();
        };

        /* 修改 */
        $("#changeBtn").click(function (event) {
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length != 1) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
                return;
            }
            var _id = selectedRows[0].id;
            Add_navTab('InsPlcBscInfo_2'+_id, "修改保单", '<%=path%>/insurance/insPlcBscInfo/toModifyPage.do?id='+_id, callback);
        });
        
        /* 查看  */
        $("#dtlBtn").click(function (event){
        	var selectedRows = grid.getSelectedRows();
            if (selectedRows.length != 1) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
                return;
            }
            var _id = selectedRows[0].id;
            Add_navTab('InsPlcBscInfo_DTL_'+_id, "保单详情", '<%=path%>/insurance/insPlcBscInfo/toDetailPage.do?id='+_id, null);
        });

        /* 批单 */
        $("#apprBtn").click(function (event){
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length != 1) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
                return;
            }
            var _id = selectedRows[0].id;
            Add_navTab('InsPlcBscInfo_4'+_id, "批单", '<%=path%>/insurance/insPlcAppr/toModifyPage.do?id='+_id, callback);
        });

        //计不计入续保
        $("#renewBtn").click(function(){
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length == 0) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW, SQ_type: "warning"});
                return;
            }
            var _ids = [];
            var isRenew=0;
            for (var index in selectedRows) {
                if(selectedRows[index].isRene==0){
                    isRenew=1;
                }else{
                    isRenew=0;
                }
                _ids.push({'id':selectedRows[index].id,'isRene':isRenew});
            }

            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: {ids: JSON.stringify(_ids)},
                url: '<%=path%>/insurance/insPlcBscInfo/modifyRenewCd.do',
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({
                        content: LogUtils.LOG_CMM_DATA_LOADING,
                        SQ_type: "waitting"
                    });
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                        grid.reload();
                    } else {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });



        });


        /* 删除 */
        $("#delBtn").click(function () {
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length == 0) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW, SQ_type: "warning"});
                return;
            }
            var _ids = [];
            for (var index in selectedRows) {
                _ids.push(selectedRows[index].id);
            }

            $.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
                if (flag == false)return;
                var wait_dialog;
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: {ids: JSON.stringify(_ids)},
                    url: '<%=path%>/insurance/insPlcBscInfo/removeByIds.do',
                    beforeSend: function () {
                        wait_dialog = $.ligerDialog.SQalert({
                            content: LogUtils.LOG_CMM_DATA_LOADING,
                            SQ_type: "waitting"
                        });
                    },
                    success: function (msg) {
                        wait_dialog.close();
                        if (msg.success == 1) {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                            grid.reload();
                        } else {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                        }
                    }
                });
            });
        });

    });

    //查询客户详情
    function showCstDtl(_cstId){
        Add_navTab("InsPlcCstBscInfo_"+_cstId, "客户信息", '<%=path%>/customer/cstbscinfo/toCustDetailPage.do?id='+_cstId, null);
    }

    //查询保单详情
    function queryPlcDtl(_id){
        Add_navTab('InsPlcBscInfo_DTL_'+_id, "保单详情", '<%=path%>/insurance/insPlcBscInfo/toDetailPage.do?id='+_id, null);
    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }

</script>

</body>
</html>
